//****************************************************************************
//
// flags example
//
//****************************************************************************

#configure board        hu_arm_v4
#configure clcd_lines   2
#configure memory       rom
#configure baudrate     38400

#include "pRTOS.h"
#include "armboard.h"

int main( void ){
   RTOS::run();
   return 0;
}

// end of standard part

class leds_task : public RTOS::task {
public:
   RTOS::flag shift, invert;
   leds_task( void ): shift( this ), invert( this ){}
private:   
   void main( void ){
      int n = 0x03, polarity = 0;
      for(;;){      
         RTOS::event e = wait( shift + invert ); 
         if( shift == e ){       
            n = (( n << 1 ) | ( n >> 7 )) & 0xFF;
		 }
		 if( invert == e ){		 
		    polarity ^= 0xFF;
		 }
    	 armboard::LEDs::write( n ^ polarity );
	  }
   }
};
leds_task leds;

class shift_task : public RTOS::task {
private:   
   void main( void ){
      for(;;){    
         sleep( 88 MS );        
         leds.shift.set();      
       }   
   }
};
shift_task inc;

class invert_task : public RTOS::task {
private:   
   void main( void ){
      for(;;){      
         sleep( 5 S );        
         leds.invert.set();      
      }   
   }
};
invert_task invert;
